package com.zhaotianhao.springboot_demo_fire.controller;


import com.zhaotianhao.springboot_demo_fire.entity.Parts;
import com.zhaotianhao.springboot_demo_fire.service.IPartsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 配件 前端控制器
 * </p>
 *
 * @author Z-7
 * @since 2022-03-22
 */
@Slf4j
@RestController
@RequestMapping("/parts")
public class PartsController {
    @Resource
    private RedisTemplate redisTemplate;
    @Autowired
    private IPartsService iPartsService;
    @PostMapping("list")
    public List<Parts> getTypeList(){
        List<Parts> parts = (List<Parts>) redisTemplate.opsForValue().get("parts");
        if (!CollectionUtils.isEmpty(parts)) {
            parts = iPartsService.list();
            redisTemplate.opsForValue().set("parts",parts);
            log.info("redis存入缓存：{}",parts);
        }
        return parts;
    }
}
